package org.crazyit.cloud.property;

import com.netflix.config.ConfigurationManager;
import com.netflix.hystrix.HystrixCommand;
import com.netflix.hystrix.HystrixCommandGroupKey;

/**
 * @Author JLL
 * @Date 2019/2/17/0017 下午 5:23
 */
public class PropertyMain {

    public static void main(String[] args) {
        //这里设置全局配置
        ConfigurationManager
        .getConfigInstance()
        //这个属性从官网的wiki去查
        .setProperty("hystrix.command.default.execution.isolation.thread.timeoutInMilliseconds",
                        2000);
        PropertyCommand c = new PropertyCommand();
        String result = c.execute();
        System.out.println(result);
    }

    static class PropertyCommand extends HystrixCommand<String> {
        public PropertyCommand() {
            super(Setter.withGroupKey(HystrixCommandGroupKey.Factory.asKey("ExampleGroup")));
        }

        @Override
        protected String run() throws Exception {
            Thread.sleep(1500);
            return "success";
        }

        @Override
        protected String getFallback() {
            //就是返回这个字符串来代替原来的请求。
            return "fall back";
        }
    }
}
